package de.playmee.dialogs;

import java.util.Set;

import de.playmee.enums.Mood;
import android.app.AlertDialog;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

public abstract class EditDialog {
	
	private AlertDialog dialog;
	private Set<Mood> moods;
	
	public EditDialog(Set<Mood> moods) {
		this.moods = moods;
	}
	
	/**
	 * sets the AlertDialog
	 * 
	 * @param dialog
	 */
	public void setDialog(AlertDialog dialog) {
		this.dialog = dialog;
	}
	
	/**
	 * displays the dialog on the screen
	 */
	public void show() {
		dialog.show();
	}
	
	/**
	 * dismisses the dialog, removing it from the screen
	 */
	public void dismiss() {
		dialog.dismiss();
	}
	
	/**
	 * initializes a checkbox
	 * 
	 * @param checkBox
	 * @param mood
	 */
	protected void initCheckBox(CheckBox checkBox, final Mood mood) {
		checkBox.setText(mood.toString());
		checkBox.setChecked(moods.contains(mood));
		checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					moods.add(mood);
				} else {
					moods.remove(mood);
				}
			}
		});
	}
}
